<!--
  ~ Copyright (c) 2019. seven studio. @chengdu
  ~ seven studio in chengdu by lb
  ~ this project for snmp tool
  -->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>编辑站点</title>
    <link rel="stylesheet" href="/res/frame/layui/css/layui.css">
    <link rel="stylesheet" href="/res/frame/static/css/style.css">
    <link rel="icon" href="/res/frame/static/image/code.png">
</head>
<body class="body">
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">站点名称:</label>
        <div class="layui-input-inline">
            <input type="text" id='clientName' placeholder="站点名称" lay-verify="required"
                   class="layui-input" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">站点地址:</label>

        <div class="layui-input-inline">
            <input type="text" id='siteAddr' lay-verify="required" placeholder="站点地址"
                   class="layui-input" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">链接类型:</label>
        <div class="layui-input-inline">
            <select id='linkType' name="linkType" lay-verify="required" lay-filter="linkType">
                <option value="1">内链</option>
                <option value="2">外链</option>
                <option value="3" >死链</option>
                <option value="4" >文件</option>
                <option value="5" >暗链</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
    <label class="layui-form-label">开启正则:</label>
    <div class="layui-input-inline">
        <select id='isNeedRegex' name="isNeedRegex" lay-verify="required" lay-filter="isNeedRegex">
            <option value="0">是</option>
            <option value="1">否</option>
        </select>
    </div>
</div>

    <div class="layui-form-item">
        <label class="layui-form-label">数量限制:</label>
        <div class="layui-input-inline">
            <select id='isNeedMax' name="isNeedMax" lay-verify="required" lay-filter="isNeedMax">
                <option value="0">是</option>
                <option value="1">否</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">连接最大数:</label>
        <div class="layui-input-inline">
            <input type="text" id='mixUrlCount' lay-verify="number" placeholder="连接最大数量"
                   class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">排序:</label>
        <div class="layui-input-inline">
            <input type="text" id='queueSort' lay-verify="number" placeholder="排序"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">线程数量:</label>
        <div class="layui-input-inline">
            <input type="text" id='threadNum' placeholder="线程数量"
                   class="layui-input">
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">redis地址:</label>
        <div class="layui-input-inline">
            <input type="text" id='redisDbAddr' placeholder="redis地址"
                   class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">数据库地址:</label>
        <div class="layui-input-inline">
            <input type="text" id='mysqlDbIp' placeholder="数据库DB地址"
                   class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">数据库端口:</label>
        <div class="layui-input-inline">
            <input type="text" id='mysqlDbPort' placeholder="数据库端口"
                   class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">数据库名称:</label>
        <div class="layui-input-inline">
            <input type="text" id='mysqlDbName' placeholder="数据库名称"
                   class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">数据库用户:</label>
        <div class="layui-input-inline">
            <input type="text" id='mysqlUserName' placeholder="数据库用户"
                   class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">数据库密码:</label>
        <div class="layui-input-inline">
            <input type="text" id='mysqlDbPassword' placeholder="数据库密码"
                   class="layui-input">
        </div>

    </div>

</form>

<div class="layui-layer-btn layui-layer-btn-c">
    <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" id="sub">提交</button>
</div>


<script src="/res/frame/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/res/js/index.js"></script>
<script type="text/javascript">

    layui.use(['form', 'layedit', 'laydate', 'element', 'cookie'], function () {
        // 操作对象
        var form = layui.form
            , table = layui.table
            , layer = layui.layer
            , vipTable = layui.vip_table
            , $ = layui.jquery,
            cookie = layui.cookie,
            laydate = layui.laydate;

        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }

        init();
        $('#sub').on('click', function () {
            var params;
            var url;
            params = {
                "id":  GetQueryString("id"),
                "clientName": $("#clientName").val(),
                "siteAddr": $("#siteAddr").val(),
                "linkType": $("#linkType").val(),
                "isNeedRegex": $("#isNeedRegex").val(),
                "mixUrlCount": $("#mixUrlCount").val(),
                "isNeedMax": $("#isNeedMax").val(),
                "queueSort": $("#queueSort").val(),
                "threadNum": $("#threadNum").val(),
                "redisDbAddr": $("#redisDbAddr").val(),
                "mysqlDbIp": $("#mysqlDbIp").val(),
                "mysqlDbPort": $("#mysqlDbPort").val(),
                "mysqlDbName": $("#mysqlDbName").val(),
                "mysqlDbPassword": $("#mysqlDbPassword").val(),
                "mysqlUserName": $("#mysqlUserName").val()
            }
            url = "/site/update";
            $.ajax({
                url: url,
                type: "post",
                contentType: "application/json",
                data: JSON.stringify(params),
                success: function (result) {
                    console.log(result)
                    if (result.code == 200) {
                        layer.msg(result.msg);
                        setTimeout(function () {
                            parent.location.reload();
                        }, 500);
                    } else {
                        layer.msg(result.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.log(XMLHttpRequest.responseText);

                }
            });


        });

        function init() {
            if (GetQueryString("id") != "0") {
                $.ajax({
                    url: "/site/select?id=" + GetQueryString("id"),
                    type: "get",
                    success: function (result) {
                        console.log(result)
                        if (result.code === "200") {
                            console.log(result)
                            $("#clientName").val(result.data.clientName);
                            $("#siteAddr").val(result.data.siteAddr);
                            $("#linkType").val(result.data.linkType);
                            $("#isNeedRegex").val(result.data.isNeedRegex)
                            $("#mixUrlCount").val(result.data.mixUrlCount);
                            $("#isNeedMax").val(result.data.isNeedMax);
                            form.render()
                            $("#queueSort").val(result.data.queueSort);
                            $("#threadNum").val(result.data.threadNum);
                            $("#redisDbAddr").val(result.data.redisDbAddr);
                            $("#mysqlDbIp").val(result.data.mysqlDbIp);
                            $("#mysqlDbPort").val(result.data.mysqlDbPort);
                            $("#mysqlDbName").val(result.data.mysqlDbName);
                            $("#mysqlDbPassword").val(result.data.mysqlDbPassword);
                            $("#mysqlUserName").val(result.data.mysqlUserName);
                            form.render()
                        }

                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.log(XMLHttpRequest.responseText);
                    }
                });


            }
        }

    });


</script>
</body>
</html>